package main

import "fmt"

type treeNode struct {
	value       int
	left, right *treeNode
}

func (tree treeNode) print() {
	fmt.Println(tree.value)
}

func (tree *treeNode) setValue(value int) {
	if tree == nil {
		fmt.Println("空指针")
		return
	}
	tree.value = value
}

func createNode(value int) *treeNode {
	return &treeNode{value: value}
}

func main() {

	var tree treeNode
	tree = treeNode{value: 3}
	tree.left = &treeNode{}
	tree.right = &treeNode{5, nil, nil}
	tree.right.left = new(treeNode)
	tree.left.right = createNode(2)

	// tree.print()
	tree.right.left.setValue(4)
	// tree.print()

	var pRoot *treeNode
	pRoot.setValue(200)

	tree.traverse()

}

func (node *treeNode) traverse() {
	if node == nil {
		return
	}
	node.left.traverse()
	node.print()
	node.right.traverse()
}
